<?php
/* SVN FILE: $Id: settings.php 232 2009-09-28 18:07:47Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Plugin Settings
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 232 $
* @lastrevision $Date: 2009-09-28 18:07:47 +0000 (Mon, 28 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-28 18:07:47 +0000 (Mon, 28 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_admin/plugin/settings.php $
*/


if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class admin_ibmarket_plugin_settings extends ipsCommand
{
	/**
	 * Skin object
	 *
	 * @access	private
	 * @var		object			Skin templates
	 */
	private $html;
	
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		$this->registry->getClass('class_permissions')->checkPermissionAutoMsg( 'manage_plugin' );
		
		$this->html = $this->registry->output->loadTemplate('cp_skin_plugins');
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'admin_market', 'admin_plugins' ) );
		
		if(!is_array($this->caches['market_plugin'][$this->request['plugin']]))
		{
			$this->registry->output->showError($this->lang->words['cannot_find_plugin']);
		}
		
		$settings = null;
		require_once(IPSLib::getAppDir('ibmarket')."/sources/plugin/adminSettings.php");
		if(file_exists(IPSLib::getAppDir('ibmarket')."/plugins/".$this->request['plugin']."/adminSettings.php"))
		{
			require_once(IPSLib::getAppDir('ibmarket')."/plugins/".$this->request['plugin']."/adminSettings.php");
			$class = 'admin_settings__'.$this->request['plugin'];
			if(class_exists($class))
			{
				$settings = new $class($this->registry);
			}
		}
		
		if($this->request['request_method'] == 'get')
		{
			$this->registry->output->html = $this->html->pluginSettingsPage( $settings );
			
			$this->registry->getClass('output')->html_main .= $this->registry->getClass('output')->global_template->global_frame_wrapper();
			$this->registry->getClass('output')->sendOutput();
		}
		else
		{
			$plugin = array(
								'name' => $this->request['name'],
								'seo_name' => IPSText::makeSeoTitle($this->request['name']),
							);
			if(!is_null($settings))
			{
				$settings->settingsSave($plugin);
			}
			
			$this->DB->update('market_plugins',$plugin,"directory='".$this->request['plugin']."'");
			
			ipsRegistry::cache()->rebuildCache('market_plugin','ibmarket');
			
			$this->registry->output->redirect( $this->settings['base_url']."module=plugin&amp;section=setup", $this->lang->words['settings_saved'] );
		}
	}
}